package edu.progra2.ventas.action;

import org.apache.struts2.convention.annotation.*;

import javax.persistence.*;
import java.util.*;

import edu.progra2.common.util.Utilitario;
import edu.progra2.ventas.model.Empleado;


/*
 * http://localhost:8080/sesion6-struts2-hr/list-employee.action
 */
@Action(value="listarEmp",
results={@Result(name="exito", 
location="/listarEmp.jsp")
} )
public class ListarEmpleadoAction {
	private List<Empleado> empleados;
	
	public String execute(){
		String result="exito";
		EntityManager em=
					Utilitario.getInstance().getEntityManager();
		String jpql="SELECT o FROM Empleado o";
		Query query=em.createQuery(jpql);
		empleados = query.getResultList();
		return result;
	}
	
	@Action(value="atras",
			results={@Result(name="exito",location="/menu-adm.jsp")
			} )
			public String atras(){
			String result="exito";
			return result;
			}

	public List<Empleado> getEmpleados() {
		return empleados;
	}

	public void setEmpleados(List<Empleado> empleados) {
		this.empleados = empleados;
	}

	

}
